/////////////////////////
// Author: Evan Bowling
// Purpose: collection of class objects to contain map vector data
//          to aid in the display and interaction of web mapping apps
/////////////////////////

    function LPObject()
    {
    	this.point; // GMarker object
    	this.line;
    	this.visible = false;
    }
    
    function CObject()
    {
    	this.overlay;
    	this.visible = false;
    	this.sd; // number of standard deviations out
    }
    
    // -----
    // Object to hold the values for changing and rearranging display elements such as circles, lines.
    // -----
    function DispObject(map_id, map_api)
    {
		/////////////////////
		// Object Public Variables
		/////////////////////
		
    	this.map_id = "map";
		// validate the map_api variable sent
		if((map_api === "g2") || (map_api ==="g3"))
		{
			this.map_api = map_api;
		}
		else
		{
			this.map_api = "g2";
		}
    	this.c_objects = new Array();
    	this.circles_display = 0; // or 1 or 2 or 3
    	this.lp_objects = new Array();
		
		/////////////////////
		// Object Functions
		/////////////////////
    	
		this.showCircles = function()
		{
			switch(this.map_api)
			{
				case "g2":
					for(var i=0;i<this.c_objects.length;i++)
					{
						if(this.c_objects[i].visible == false)
						{
							map.addOverlay(this.c_objects[i].overlay);
							this.c_objects[i].visible = true;
						}
					}
					break;
				default:
					break;
			}
		}

		this.hideCircles = function()
		{
			switch(this.map_api)
			{
				case "g2":
					for(var i=0;i<this.c_objects.length;i++)
					{
						if(this.c_objects[i].visible == true)
						{
							map.removeOverlay(this.c_objects[i].overlay);
							this.c_objects[i].visible = false;
						}
					}
					break;
				default:
					break;
			}
		}
	
		// functions for POINTS / LINES
		this.showPoints = function()
		{
			for(var i=0;i<this.lp_objects.length;i++)
			{
				//if(this.lp_objects[i].visible == false)
				//{
					switch(this.map_api)
					{
						case "g2":
							map.addOverlay(this.lp_objects[i].point);
							this.lp_objects[i].visible = true;
							break;
						case "g3":
							this.lp_objects[i].point.setVisible(true);
							this.lp_objects[i].visible = true;
							break;
					}
				//}
			}
		}

		this.hidePoints = function()
		{
			for(var i=0;i<this.lp_objects.length;i++)
			{
				//if(this.lp_objects[i].visible == true)
				//{
					switch(this.map_api)
					{
						case "g2":
							map.removeOverlay(this.lp_objects[i].point);
							this.lp_objects[i].visible = false;
							break;
						case "g3":
							this.lp_objects[i].point.setVisible(false);
							this.lp_objects[i].visible = false;
							break;
					}
				//}
			}
		}
		
		this.addPoints = function()
		{
			var data = oe.generateDataset(); // generate a new data set with offset errors
			var original = oe.getDataSet(); // this seems redundant, but lets us change which data set we're using in the main load function alone
			var x;
			for(var i =0;i<data.length;i++)
			{
				switch(this.map_api)
				{
					case "g2":
						// Create our "tiny" marker icon
						//var blueIcon = new GIcon(G_DEFAULT_ICON);
						//blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
						//blueIcon.iconSize = new GSize(32,32);
						//blueIcon.shadow = "";
						//blueIcon.shadowSize = new GSize(0,0);
						//blueIcon.infoWindowAnchor = new GPoint(4,4);
						//blueIcon.anchor = new GPoint(2,2);


						//-add point to map v2
						var marker = new GMarker( new GLatLng(data[i].lat,data[i].lon) );//,{icon:blueIcon});
						var lp = new LPObject();
						lp.point = marker;
						this.lp_objects.push( lp );
						break;
					case "g3":
						// create the marker object
						var marker = new google.maps.Marker({
							position: new google.maps.LatLng(data[i].lat,data[i].lon), 
							map: map,
							title:"Hello World!"
						}); 
						
						// create an array of points for the line object
						var array = new google.maps.MVCArray();
						array.push(new google.maps.LatLng(data[i].lat,data[i].lon));
						array.push(new google.maps.LatLng(original.coordinates[i][0],original.coordinates[i][1]));
						
						// create the line object
						polylineOptions = {
								map: map,
								strokeColor: "#000000",
								strokeOpacity: 0.8,
								strokeWeight: 2,
								path: array
						}
						var line = new google.maps.Polyline(polylineOptions);
						
						// add the objects to a local class for storage
						var lp = new LPObject();
						lp.point = marker;
						lp.visible = true;
						lp.line = line;

						this.lp_objects.push(lp);
						break;
				}
			}
			
			// ensure the generated points are visible
			this.showPoints();
			
			return data;
		}
		
		this.recalculatePoints = function()
		{
			// hide and remove the old points
			this.hidePoints();             // hide the markers so that multiple objects do maintain
			// g3 markers will also have to be properly removed - just hiding won't do
			this.lp_objects = new Array(); // resets the lp_objects object
			
			// add a new set of points
			this.addPoints();
		}
    	

    	
    	// make sure that the first argument is a string type
    	//if(typeof arguments[0] === "string")
    	//{
    	//	this.map_id = arguments[0]; // set the string value of div holding the map canvas
    	//}
    	
    	
    	
    	
		
    	this.addCircle = function()
    	{
    		
    		// check to make sure the argument is a 
    		if(typeof arguments[0] === "function")
    		{
    			this.circles.push( arguments[0] );
    		}
    	};
    	
    };